package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.AccessLogDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.AccessLog;
import com.itheima.service.AccessLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Service(interfaceClass = AccessLogService.class)
@Transactional
public class AccessLogServiceImpl implements AccessLogService {
    @Autowired
    AccessLogDao accessLogDao;
    @Override
    public void add(AccessLog accessLog) {
        accessLogDao.add(accessLog);
    }

    public PageResult findPage(QueryPageBean queryPageBean){
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize(),"date desc");
        Page<AccessLog> accessLogPage=accessLogDao.findPage(queryPageBean.getQueryString());
        return new PageResult(accessLogPage.getTotal(), accessLogPage);
    }
}
